<?php

include_once('Command.php');

class HelpCommand extends Command
{
	public function run(){
		$files=self::dirList();
		echo '<b>cls</b>';
		echo ' - ';
		echo 'Изчиства екрана';
		echo '<br/>';
		
		foreach($files as $file){
			$class = substr($file, 0, strpos($file, "Command.php"));
			include_once(dirname(__FILE__).'/'.$file);
			$name = $class.'Command';
			$out = new $name;
			echo '<b>'.strtolower($class).'</b>';
			echo ' - ';
			echo $out->help();
			echo '<br/>';
		}
	}
	
	private function dirList () 
	{

	    // create an array to hold directory list
	    $results = array();

	    // create a handler for the directory
	    $handler = opendir(dirname(__FILE__));

	    // keep going until all files in directory have been read
	    while ($file = readdir($handler)) {

		// if $file isn't this directory or its parent, 
		// add it to the results array
		if ($file != '.' && $file != '..' && $file != 'Command.php' && $file != 'DispatchAction.php')
		    $results[] = $file;
	    }

	    // tidy up: close the handler
	    closedir($handler);

	    // done!
	    return $results;

	}

	public function help(){
		echo 'Помощна команда.';
	}

}
?>
